package org.example.blog.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.blog.pojo.Result;
import org.example.blog.pojo.Tag;
import org.example.blog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/tag")
public class TagController {
    @Autowired
    private TagService tagService;

    // 查询所有标签
    @GetMapping
    public Result list() {
        List<Tag> tagList = tagService.list();
        return Result.success(tagList);
    }

    //模糊查询
    @GetMapping("/mohu")
    public Result list1(@RequestParam String name){
        List<Tag> tagList = tagService.list1(name);
        return Result.success(tagList);
    }
    // 新增标签
    @PostMapping
    public Result add(@RequestBody Tag tag) {
        tagService.add(tag);
        return Result.success();
    }

    // 删除标签
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        tagService.delete(id);
        return Result.success();
    }

    // 更新标签
    @PutMapping
    public Result update(@RequestBody Tag tag) {
        tagService.update(tag);
        return Result.success();
    }
}